package com.itheima.ydd.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页数据转换器(用于前后端容器命名不一致数据无法读取)
 * @param <T>
 */
@Data
public class PageReturn<T> {
    //总条数
    private Long count;
    //当前页码
    private Long currentPage;
    //分页数据
    private List<T> data;
    //分页大小
    private Long pageSize;
    //分页数
    private Long totalPages;

    public static<T> PageReturn<T> change(Page<T> object){
        PageReturn<T> pageReturn = new PageReturn<>();
        pageReturn.setCount(object.getTotal());
        pageReturn.setCurrentPage(object.getCurrent());
        pageReturn.setData(object.getRecords());
        pageReturn.setPageSize(object.getSize());
        pageReturn.setTotalPages(object.getPages());
        return pageReturn;
    }
}
